home *** CD-ROM | disk | FTP | other *** search
- Path: news.th-darmstadt.de!news
- From: Enno Sandner <enno@intellektik.informatik.th-darmstadt.de>
- Newsgroups: comp.lang.c++
- Subject: Re: Question about abstract base class
- Date: Thu, 18 Apr 1996 09:35:23 +0200
- Organization: Fachbereich Informatik, TH Darmstadt
- Message-ID: <3175F0BB.446B9B3D@intellektik.informatik.th-darmstadt.de>
- References: <4l3u1s$j80@hermes.acs.unt.edu>
- NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (X11; I; SunOS 4.1.3 sun4m)
-
- Chen-five Chi wrote:
- >
- > I just wrote a simple program like this:
- >
- > class shape
- >
- > {
- > public:
- > virtual void print() const = 0;
- > ........
- > }
- > clase TwoDimensionObject: public shape
- > {
- > public:
- > virtual void area() const = 0;
- > ...
- > }
- > class Square: public TwoDimensionObject
- > {
- > private:
- > int side;
- > public:
- > virtual void area()
- > {
- > cout << "Square area: " << (side * side);
- > }
- > }
- > ...
- > void main()
- > {
- > Square s1;
- > ....
- > }
- >
- > ==============================
- > And I get a compiler error in BC 4.51 said "s1 is abstract base class...."
- > After I move the keyword "const", the program runs normally without any
- > problem.
- >
- > I would like to know
- > "Why I Could not put 'const' in the ABC? and the different these two?
- >
- > Your kindness help is appreciated.
- >
-
- If you declare a pure virtual member-function as const in some
- class, you've to provide an implementation for a function with
- o the same name
- o the same arguments
- o the same qualifier (i.e. the function also has to be const-
- qualified).
- in some subclass.
- Therefore your problem should disappear when you declare
- 'Square::area' as const (and provide an implementation for the
- 'print' member-function).
-
- Enno
-